package cate.game.server.rpc;

import cate.game.common.rpc.RpcListener4Process;
import cate.game.server.rpc.dispatch.RpcFafDispatcher;
import cate.game.server.rpc.dispatch.RpcRrDispatcher;
import cp.solution.rpc.RpcMsgHead;
import cp.solution.rpc.listener.RpcFireAndForgetListener;
import cp.solution.rpc.listener.RpcRequestResponseListener;

public class RpcListener4ProcessImpl extends RpcListener4Process {

    private RpcFafDispatcher fafDispatcher = new RpcFafDispatcher();
    @Override
    public void onFireAndForget(String path, RpcFireAndForgetListener handler, int priority) {
        RpcListener4Process.regPath(path);
        fafDispatcher.addListener(path, handler, priority);
    }

    private RpcRrDispatcher rrDispatcher = new RpcRrDispatcher();
    @Override
    public void onRequestResponse(String path, RpcRequestResponseListener handler) {
        RpcListener4Process.regPath(path);
        rrDispatcher.addListener(path, handler);
    }

    @Override
    public void dispatchFireAndForget(RpcMsgHead head, byte[] msgBody) {
        fafDispatcher.dispatch(head, msgBody);
    }

    @Override
    public byte[] dispatchRequestResponse(RpcMsgHead head, byte[] msgBody) {
        return rrDispatcher.dispatch(head, msgBody);
    }


}
